<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=">
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>个人信息-修改手机</title>
	<link rel="stylesheet" href="__PUBLIC__/Mobile/css/zhang.css">
	<script src="__PUBLIC__/Mobile/js/jquery-1.7.2.min.js"></script>
	<script src="__PUBLIC__/Mobile/Layer/layer.min.js"></script>
</head>

<body >
<section>
<!--修改手机-->
<div class="lm">
	<a href="javascript:history.back(-1);">
		<img src="__PUBLIC__/Mobile/images/return.png" style="height:22px; padding-left:2%; line-height:22px; width:6%; padding-top:2%;" class="left">
	</a>
    <span class="left size20">修改手机 </span>
</div>
<div class="Logon1">
	<p><b><img src="__PUBLIC__/Mobile/images/Phone.png"></b>
    <span>
	  <input name="phone" type="text" class="size18" placeholder="请输入新号码" id="mobile">
     <a href="javascript:void(0);" id="code">获取验证码</a>   
      </span>
   </p>
	<p><b><img src="__PUBLIC__/Mobile/images/SMS.png"></b>
	  <input name="verify" type="text" placeholder="请输入短信验证码" class="size18">
    
   </p>
</div>
<button class="immediately2 size26" style="border:none;" id="changetel">修改手机</button>
</section>
<script>
	var yzm;
	$("#code").click(function(){
		var validCode=true;
		var time=60;
		var codes=$(this);
		var phone = $("input[name=phone]").val();
		if(!phone){
			layer.msg('手机号码不能为空',2);
			return false;
		}
		if(!(/^1[3|4|5|7|8]\d{9}$/.test(phone))){ 
			layer.msg('请填写正确的手机号码',2);  
	        return false; 
	    } 
		
		$.ajax({
			url: "{:U('Mycenter/change_newphonecod')}",
	        type: "POST",
	        data: {phone:phone},
	        dataType: "json",
	        success: function(result){
	        	if(result.isok=='nochange'){
	             	 layer.alert('您没有更改号码',2);
	            }else if(result.isok=='have'){
	             	 layer.msg('此号码已经被其他账号使用',2);
	            }else if(result.isok=='ok'){
	            	 if (validCode) {
	        			validCode=false;
	        			codes.addClass("msgs1");
	        			var t=setInterval(function  () {
	        			time--;
	        			codes.html("等待"+time+"秒");
	        			if (time==0) {
	        				clearInterval(t);
	        			codes.html("重新获取");
	        				validCode=true;
	        			codes.removeClass("msgs1");
	        				}
	        			},1000)
	        		 }
	            	 layer.alert('验证码为发送成功',6);
	            	 yzm = result.code;
	            }else{
	            	layer.alert('验证码获取失败',2);
	            }    
	        }
	    });
	});
	
	
	//点击更新号码
	$("#changetel").click(function(){
		var phone = $("#mobile").val();
		var verify = $("input[name=verify]").val();
		if(!phone){
			layer.msg('手机号码不能为空',2);
			return false;
		}
	   if(!(/^1[3|4|5|7|8]\d{9}$/.test(phone))){ 
			layer.msg('请填写正确的手机号码',2);  
		    return false; 
	   } 
	   if(!verify){
			layer.msg('验证码不能为空',2);
			return false;
	   }
	   
	   $.ajax({
		   url: "{:U('Mycenter/change_phone')}",
	       type: "POST",
	       data: {phone:phone,yzm:verify},
	       dataType: "json",
	       success: function(result){
		       if(result=='ok'){
		            layer.alert('账号更改成功,请重新登录',6);
		            location.href="{:U('User/login')}"; 
		       }else if(result=='e'){
			   layer.msg('验证码错误',2);
			   }else{
		            layer.msg('更改失败',2);
		       }    
	       }
   	   });
	});
	/* $("#change_phone").click(function(){
		var phone = $("input[name=phone]").val();
		var verify = $("input[name=verify]").val();
		 if(!phone){
			layer.msg('手机号码不能为空',2);
			return false;
		}
		if(!(/^1[3|4|5|7|8]\d{9}$/.test(phone))){ 
			layer.msg('请填写正确的手机号码',2);  
	        return false; 
	    } 
		if(!verify){
			layer.msg('手机号码不能为空',2);
			return false;
		}
		if(verify != $yzm){ 
			layer.msg('验证码不正确',2);  
	        return false; 
	    }
		
		$.ajax({
			 	url: "{:U('Mycenter/change_phone')}",
	        type: "POST",
	        data: {phone:phone},
	        dataType: "json",
	        success: function(result){
	        	if(result.isok=='ok'){
	             	  layer.alert('账号更改成功,请重新登录',6);
	             	  location.href="{:U('User/login')}"; 
	            }else{
	             	  layer.msg('更改失败',2);
	            }    
	        }
	    });
	}); */
</script>
</body>
</html>
